import {createRouter, createWebHashHistory} from 'vue-router'
import Login from '../components/login/Login.vue'
import Home from '../components/home/Home.vue'
import Order from '../components/home/order/Order.vue'
import Goods from '../components/home/good/Goods.vue'
import AddGood from '../components/home/good/AddGood.vue'
import GoodCategory from '../components/home/good/GoodCategory.vue'
import ManagerList from '../components/home/manager/ManagerList.vue'
import ManagerReqList from '../components/home/manager/ManagerReqList.vue'
import ManagerOrder from '../components/home/manager/ManagerOrder.vue'
import DataCom from '../components/home/financial/DataCom'
                                                  
import Store from './Storage'

const Router = createRouter({
    history: createWebHashHistory(),
    routes:[{
        path : '/login',
        component:Login,
        name: 'login'
    },{
        path : '/home',
        component:Home,
        name: 'home',
        children:[{
            path:'order/:type',
            component:Order,
            name:'order'
        },{
            path:'goods/:type',
            component:Goods,
            name:'goods'
        },{
            path:'addGood/:type',
            component:AddGood,
            name:'addGood'
        },{
            path:'category',
            component: GoodCategory,
            name:'goodCategory'
        },{
            path:'ownerlist',
            component:ManagerList,
            name:'managerlist'
        },{
            path:'ownerreq',
            component:ManagerReqList,
            name:'managerReqList'
        },{
            path:'ownerorder',
            component: ManagerOrder,
            name:"managerOrder"
        },{
            path:'data',
            component: DataCom,
            name:"dataCom"
        }]
    }]
})

Router.beforeEach((from)=>{
    let isLogin = Store.getters.isLogin
    if(isLogin || from.name == 'login'){
        return true
    }else{
        return{ name : 'login'}
    }
})
export default Router